from django.core.mail import send_mail
from django.conf import settings
from celery_tasks.main import celery_app
import logging


# logger = logging.getLogger('django')


@celery_app.task(bind=True, name="send_verify_email", retry_backoff=3)
def send_verify_email(self, to_email, verify_url):
    # send_mail('标题', '普通邮件正文', '发件人', '收件人列表', '富文本邮件正文(html)')
    subject = "mallsite email verification"
    html_message = '<p>hell, dear user!</p>' \
                    '<p>thanks for using mallsite.</p>' \
                    '<p>your email is: %s . please click this link to active your email: </p>' \
                    '<p><a href="%s">%s<a></p>' % (to_email, verify_url, verify_url)

    try:
        send_mail(subject, '', settings.EMAIL_FROM, [], html_message)
    except Exception as e:
        # logger.error(e)
        raise self.retry(exc=e, max_retries=3)
